package com.wr.services.impl;

import com.wr.mappers.PermissionMapper;
import com.wr.mappers.RolePermissionEntityMapper;
import com.wr.pojos.PermissionEntity;
import com.wr.pojos.RolePermissionEntity;
import com.wr.services.PermissionService;
import com.wr.utils.PageInfo;
import org.apache.ibatis.session.RowBounds;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 权限Service实现类
 *
 * @author StarZou
 * @since 2014年6月10日 下午12:05:03
 */
@Service
public class PermissionServiceImpl implements PermissionService {

    @Resource
    private PermissionMapper permissionMapper;

    @Resource
    private RolePermissionEntityMapper rolePermissionEntityMapper;

    @Override
    public List<PermissionEntity> selectPermissionsByRoleId(int roleId) {
        return permissionMapper.selectPermissionsByRoleId(roleId);
    }

    @Override
    public List<PermissionEntity> selectPermissionList(PageInfo pageInfo) {
        pageInfo.setCount(permissionMapper.countPermissions());
        return permissionMapper.selectPermissions(new RowBounds(pageInfo.getOffset(),pageInfo.getPageSize()));
    }

    @Override
    public List<PermissionEntity> selectPermissionList() {
        return permissionMapper.selectPermissions();
    }

    @Override
    public List<RolePermissionEntity> selectRolePermissions(int roleId) {
        return rolePermissionEntityMapper.selectRolePermissions(roleId);
    }
}
